--- @param extension Package
--- @param HY HY_Utility
--- @param U Utility
return function(extension, HY, U)
    local hy_hieda_no_akyuu = General:new(extension, "hy_hieda_no_akyuu", "jin_k", 1, 1, General.Female)
    local hyperthymesia = fk.CreateSkill {
        name = "hyperthymesia",
    }
    hyperthymesia:addEffect(fk.AfterCardsMove, {
        anim_type = "defensive",
        can_trigger = function(self, event, target, player, data)
            if player.room.current.phase == Player.NotActive then
                return false
            end
            if player:hasSkill(hyperthymesia.name) and player:usedSkillTimes(hyperthymesia.name, Player.HistoryPhase) < 1 then
                for _, move in ipairs(data) do
                    if move.from and move.moveReason ~= fk.ReasonUse and (move.from == player.room.current or move.from == player) then
                        for _, info in ipairs(move.moveInfo) do
                            if info.fromArea == Card.PlayerEquip or info.fromArea == Card.PlayerHand then
                                return true
                            end
                        end
                    end
                end
            end
        end,
        on_cost = function(self, event, target, player, data)
            local targets = {}
            for _, move in ipairs(data) do
                if move.from and not move.from.dead and move.moveReason ~= fk.ReasonUse and (move.from == player.room.current or move.from == player) then
                    for _, info in ipairs(move.moveInfo) do
                        if info.fromArea == Card.PlayerEquip or info.fromArea == Card.PlayerHand then
                            table.insertIfNeed(targets, move.from)
                            break
                        end
                    end
                end
            end
            local room = player.room
            for _, t in ipairs(targets) do
                local result = room:askToSkillInvoke(player, {
                    skill_name = hyperthymesia.name,
                    prompt = "hyperthymesia_prompt::" .. t.id
                })
                if result then
                    event:setCostData(self, t.id)
                    return true
                end
            end
        end,
        on_use = function(self, event, target, player, data)
            local room = player.room
            local skillTarget = room:getPlayerById(event:getCostData(self))
            if not skillTarget.dead then
                room:drawCards(skillTarget, 1, hyperthymesia.name)
                if player:getMark("@samsara") < 5 then
                    local extraDraw = room:askToSkillInvoke(player, {
                        skill_name = hyperthymesia.name,
                        prompt = "hyperthymesia_extra_prompt::" .. event:getCostData(self)
                    })
                    if extraDraw and not skillTarget.dead then
                        room:addPlayerMark(player, "@samsara", 1)
                        room:drawCards(skillTarget, 1, hyperthymesia.name)
                    end
                end
            end
        end,
    })
    local samsara = fk.CreateSkill {
        name = "samsara",
    }
    samsara:addEffect(fk.PreDamage, {
        anim_type = "support",
        can_trigger = function(self, event, target, player, data)
            if player:hasSkill(samsara.name) then
                return data.to == player
            end
        end,
        on_cost = Util.TrueFunc,
        on_use = function(self, event, target, player, data)
            local room = player.room
            room:loseHp(player, data.damage, samsara.name)
            data:preventDamage()
        end,
    })
    samsara:addEffect(fk.EnterDying, {
        anim_type = "support",
        can_trigger = function(self, event, target, player, data)
            if player:hasSkill(samsara.name) then
                return target == player and player:getMark("@samsara") < 5
            end
        end,
        on_cost = function(self, event, target, player, data)
            return player.room:askToSkillInvoke(player, {
                skill_name = samsara.name,
                prompt = "samsara_prompt"
            })
        end,
        on_use = function(self, event, target, player, data)
            local room = player.room
            room:addPlayerMark(player, "@samsara", 1)
            room:recover({
                who = player,
                num = 1 - player.hp,
                skillName = samsara.name,
                recoverBy = player,
            })
            if player.faceup == false then
                player:turnOver()
            end
            if player.chained then
                player:setChainState(false)
            end
            local count = #table.filter(player.player_cards[Player.Hand], function(id)
                return not player:prohibitDiscard(Fk:getCardById(id))
            end)
            if count > 0 then
                room:throwCard(table.filter(player.player_cards[Player.Hand], function(id)
                    return not player:prohibitDiscard(Fk:getCardById(id))
                end), samsara.name, player, player)
                if not player.dead then
                    room:drawCards(player, count, samsara.name)
                end
            end
        end,
    })
    samsara:addEffect("maxcards", {
        correct_func = function(self, player)
            return player:hasSkill(samsara.name) and player:getMark("@samsara") or 0
        end,
    })
    extension:loadSkillSkels { hyperthymesia, samsara }
    hy_hieda_no_akyuu:addSkill("hyperthymesia")
    hy_hieda_no_akyuu:addSkill("samsara")
    Fk:loadTranslationTable {
        ["hy_hieda_no_akyuu"] = "稗田阿求",
        ["#hy_hieda_no_akyuu"] = "人世的记忆",
        ["illustrator:hy_hieda_no_akyuu"] = "ZYANNA",
        ["designer:hy_hieda_no_akyuu"] = "黑曜人形",
        ["cv:hy_hieda_no_akyuu"] = "",

        ["hyperthymesia"] = "永识",
        [":hyperthymesia"] = "每角色每阶段限一次，在当前回合角色或你不因使用而失去牌后，你可以令该角色摸一张牌，然后若你的“轮回”标记小于5，你可以获得一个“轮回”标记并令该角色摸一张牌。你的手牌上限+X（X为“轮回”标记数）。",
        ["hyperthymesia_prompt"] = "永识：你可以令%dest摸一张牌",
        ["hyperthymesia_extra_prompt"] = "永识：你可以获得一个“轮回”标记并令%dest摸一张牌",

        ["samsara"] = "轮回",
        [":samsara"] = "你即将受到的伤害视为失去体力。在你进入濒死状态时，若你的“轮回”标记小于5，你可以获得一个“轮回”标记，复原武将牌并回复至1点体力，然后弃置所有手牌并摸等量的牌。",
        ["@samsara"] = "轮回",
        ["samsara_prompt"] = "轮回：你可以回复至1点体力",
    }
end
